package com.wzq.tools.interconversion;

import org.apache.commons.lang3.ObjectUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * object和List转换
 *
 * @author weizq
 * @since 2021/2/26
 */
public class ObjectAndListInterconversion {

    /**
     * 将obj转换成list
     *
     * @param obj 转换的对象
     * @param cla 对象的类型
     * @return java.util.List<T>
     * @throws
     * @author weizq
     * @since 2021/2/26
     */
    public static List<Map<String, Object>> objToList(Object obj) {
        if (!ObjectUtils.allNotNull(obj)) {
            return new ArrayList<>();
        }
        List<Map<String, Object>> list = new ArrayList();
        if (obj instanceof ArrayList<?>) {
            for (Object o : (List<?>) obj) {
                list.add((Map<String, Object>) o);
            }
            return list;
        }
        return null;
    }
}
